<?php
namespace src;
use classlib\input;
use src\logic\Cadmin;
use classlib\core as C;
use classlib\core\controller;
class Cappcrash extends controller {
	
	public function main() {
		$view   = C\view::inst('extjs');
		Cadmin::chkaccess($view);
		$view->assign_by_ref('title', Cadmin::$name);
		$view->display('live/log/appcrash.ext.js');
	}
	
	public function dolist() {
		$view   = C\view::inst('json');
		Cadmin::chkaccess($view);
		list($start, $limit, $sort) = Cadmin::offset();
		$where = array();
		$ver   = trim(input::post('ver'));
		if ($ver) {
			$where[] = array('ver', '%'.$ver.'%', \classlib\orm::OP_LIKE);
		}
		$os    = trim(input::post('os'));
		if ($os) {
			$where[] = array('os', '%'.$os.'%', \classlib\orm::OP_LIKE);
		}
		$msg   = trim(input::post('msg'));
		if ($msg) {
			$where[] = array('msg', '%'.$msg.'%', \classlib\orm::OP_LIKE);
		}
		$device= trim(input::post('device'));
		if ($device) {
			$where[] = array('device', '%'.$device.'%', \classlib\orm::OP_LIKE);
		}
		$sdate  = input::post('sdate');
		if ($sdate) {
			$where[] = array('stime', strtotime($sdate), \classlib\orm::OP_GT);
		}
		$edate  = input::post('edate');
		if ($edate) {
			$where[] = array('stime', strtotime($edate), \classlib\orm::OP_LT);
		}
		$orm    = C\model::load('log.log.appcrash');
		$total  = $orm->get_total($where);
		$list   = array();
		if ($total) {
			$list = $orm->get_list($start, $limit, $where, '*', $sort);
			$uorm = C\model::load('pro.pl.userinfo');
			foreach ($list as &$item) {
				$item['stime'] = date('Y-m-d H:i:s', $item['stime']);
				if ($item['userid'] && $item['userid'] > 0) {
					$user = $uorm->get_one($item['userid']);
					$item['userid'] = $user['nickname'].'['.$user['email'].']';
				}
			}
		}
		$view->assign_by_ref('total', $total);
		$view->assign_by_ref('dataset', $list);
		$view->display();
	}
}